package cn.doitedu.hbase.day02;

import cn.doitedu.hbase.day01.ConnectionUtils;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * delete 删除的是一行中的一个cell （rowkey, 列族，列的标识符）
 * delete 删除整行数据(rowkey)
 *
 */
public class DeleteDemo {


    public static void main(String[] args) throws Exception {


        Connection connection = ConnectionUtils.getConnection();
        Table table = connection.getTable(TableName.valueOf("tb_users"));

        //第一种用法：删除数据(一个或多个cell（k-v）)
//        Delete delete = new Delete(Bytes.toBytes("u003"));
//        delete.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
//        delete.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));
//
//

        //第二种：删除指定列族的数据
        Delete delete = new Delete(Bytes.toBytes("u004"));
        delete.addFamily(Bytes.toBytes("f1"));

        //第三种用法：删除一行数据(deleteall)
//      Delete delete = new Delete(Bytes.toBytes("u003"));


        //必须调用table.delete
        table.delete(delete);


        table.close();
        connection.close();

    }

}
